<template>
  <div class="page-scan-mana">
    <el-form :inline="true" :model="dataQueryForm" ref="dataQueryForm">
      <div class="pc-page-header">
        <el-form-item label="">
          <el-button type="primary" @click="refresh('dataQueryForm')">刷新</el-button>
        </el-form-item>
      </div>
    </el-form>

    <!--列表数据-->
    <egrid border class="page-list"
           :data="tableData"
           :columns="columns"
           :columns-schema="columnsSchema"
           :columns-props="columnsProps">
    </egrid>

    <!--分页组件-->
    <div class="pc-pagination-panel">
      <pc-pagination ref="pcPagination" :url="pageUrl.queryDataList" :queryData="dataQueryForm"
                     @on-query="queryCallBackFn">
      </pc-pagination>
    </div>

    <!--汇率历史页面-->
    <pc-dialog-center :is-show="isShowHistoryDialog" :title='dialogTitle' @on-close="isShowHistoryDialog = false" width="800" height="640">
      <div>
        <history :rateName="rateName">
        </history>
      </div>
    </pc-dialog-center>

  </div>
</template>

<script type="text/ecmascript-6">
  import PcPagination from 'components/form/pagination';
  import PcButton from 'components/form/button';
  import PcDialogCenter from 'components/dialog/center.vue';
  import EgridCellView from 'components/wms/comm/EgridCellView.vue';
  import History from './history.vue';
  let that;

  // 操作按钮
  var Btn = {
    template: `<div style="display:flex; width: 100%;flex-wrap: wrap">
        <el-button type="primary" plain @click="gotoHistory(row)">历史数据</el-button>
      </div>`,
    props: ['row'],
    computed: {
    },
    methods: {
      // 跳转历史数据
      gotoHistory (val) {
        this.$emit('show-history', val);
      }
    }
  };

  export default {
    data() {
      return {
        rateName: '',
        dialogTitle: '',
        isShowHistoryDialog: false,
        dataQueryForm: {
        },
        tableData: [],
        columns: [
          {
            label: '货币对',
            prop: 'rateName'
          },
          {
            label: '更新时间',
            prop: 'createdTime'
          },
          {
            label: '现价',
            prop: 'rate'
          },
          {
            label: '操作',
            minWidth: 20,
            fixed: 'right',
            component: Btn, // 'el-button'
            listeners: {
              'show-history' (data) {
                that.viewHistoryFn(data);
              }
            },
            propsHandler: function ({ row, col, column }) {
              return {row, col, column};
            }
          }
        ],
        columnsSchema: {
        },
        selecetedRows: [],
        // columnsProps 用于定义所有 columns 公共的属性，
        // 这里属性可以参考这里： http://element.eleme.io/#/zh-CN/component/table#table-column-attributes
        columnsProps: {
          height: 40,
          minWidth: 60,
          showOverflowTooltip: true,
          component: EgridCellView
        },
        // columnsHandler 可用于在现有的 columns 进行操作，对 columns 进行增删改，这里新增了操作列
        pageUrl: {
          queryDataList: '/malisk/server/macro/queryMacroExchangeList'
        }
      };
    },
    components: {
      PcPagination, PcButton, PcDialogCenter, History
    },
    created() {
      that = this;
    },

    methods: {
      // 表头样式
      getHeaderStyle({row, column, rowIndex, columnIndex}) {
        if (rowIndex === 0) {
          return 'background: #f5f5f5; height: 50px';
        } else {
          return '';
        }
      },
      getRowClass({row, column, rowIndex, columnIndex}) {
        if (rowIndex === 0) {
          return 'background:rgb(245, 245, 245);';
        } else {
          return '';
        }
      },
      viewHistoryFn (scopeRow) {
        this.rateName = scopeRow.rateName;
        this.dialogTitle = '历史数据（货币对：' + scopeRow.rateName + '）';
        this.isShowHistoryDialog = true;
      },
      openMessage() {
        this.$notify.info({
          title: '自定义位置',
          message: '右下角弹出的消息',
          position: 'bottom-right'
        });
      },
      queryCallBackFn(res) {
        this.tableData = res.result.list;
      },
      queryDataFn() {
        this.$refs.pcPagination.queryListWithPageFn(true);
      },
      refresh(formName) {
        this.$refs[formName].resetFields();
        this.queryDataFn();
      }
    }
  };
</script>
<style>
</style>
